<template>
<div class="container">
    <!-- <h1>图书管理系统</h1>
      <ul><img class="a" src="../assets/logo.png"></ul> -->
    <div class="mydiv">
      
      <div class="title_wrap">
        <h1>图书管理系统</h1>
      </div>
      <el-form
        :label-position="labelPosition"
        label-width="80px"
        :model="formLabelAlign">
        <el-form-item class="el-form-item" label="用户名">
          <el-input  class="inputname" v-model="formLabelAlign.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input class="inputpassword" v-model="formLabelAlign.password"></el-input>
        </el-form-item>
        
          <!-- 登录 和 对话框 点击事件 -->
          <div class="button"><el-button  size="small" @click="toLogin(formLabelAlign)"
            >登录</el-button
          >
          <el-button  size="small" @click="dialogFormVisible = true"
            >注册</el-button
          ></div>
          
        
      </el-form>
    </div>
    <el-dialog title="账号注册" :visible.sync="dialogFormVisible">
      <el-form>
        <el-form-item label="账号" :label-width="formLabelWidth">
          <el-input autocomplete="off" v-model="newuser.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input autocomplete="off" v-model="newuser.password"></el-input>
        </el-form-item>
      </el-form>
      <!-- 对话框 按钮 -->
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="register(newuser)">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      labelPosition: "right",
      formLabelAlign: {
        username: "",
        password: "",
      },
      newuser: {
        username: "",
        password: "",
      },
      formLabelWidth: "120px",
      dialogFormVisible: false,
    };
  },
  // 点击事件跳转页面
  methods: {
    toLogin(aa) {
      this.$axios.post("http://127.0.0.1:7001/api/login", aa).then((res) => {
        console.log(res);
        sessionStorage.setItem('token',res.data.res._id);
        this.$router.push("/layout");
      });
      this.$router.push("/layout");
    },
    register(a) {
      this.$axios.post("http://127.0.0.1:7001/api/user", a).then((res) => {
        console.log(res);
        if (res.data.data.code == 200) {
          this.$message.success({ message: "注册完成", center: true });
          this.showDialog = false;
        } else {
          this.$message.error({ message: "注册失败", center: true });
        }
      });
      this.dialogFormVisible = false;
    },
  },
};
</script>

<style scoped>
img.a {
  width: 200px;
  height: 100px;
  object-position: right top;
}

.container {
  background-image: url(../../assets/Sign.jpg);
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.title_wrap {
  text-align: center;
}
.el-form-item__label {
  color: black;
  width: 80px;
}
.button {
  margin-left: 180px;
  margin-top: 30px;
  margin-bottom: 15px;
}
.inputpassword {
    width: 350px;

}
.inputname {
  width: 350px;
}
.mydiv {
    /* opacity:0.4; */
    box-shadow: 2px 2px 20px ;
    border : 1px solid;
    border-radius: 25px;
    width: 500px;
    margin-bottom: 150px;
    backdrop-filter: blur(3px);
}
/* >>>.el-form-item__label{
  color: white;
} */
</style>